package com.ikas.ai.framework.node.impl;

import com.ikas.ai.framework.flow.ScoreFlow;
import com.ikas.ai.framework.node.NodeType;

import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * @Description: 结束节点
 * @Author: qi.yilai
 * @Date: 2023/1/12 19:41
 * @Version: 1.0.0
 **/
public class EndNode extends AbstractNode<Boolean> {
    private String riskName;
    private String strategy;
    private double restartProb;
    private double happenProb;
    // 是否触发风险，true= 触发风险，false=没有触发风险
    private boolean success;

    public EndNode(ScoreFlow scoreFlow, String riskName, String strategy, Double restartProb, double happenProb, Long nodeId, Long nodeInstanceId, String name) {
        super(scoreFlow, nodeId, nodeInstanceId, name);
        this.riskName = riskName;
        this.strategy = strategy;
        this.restartProb = restartProb;
        this.happenProb = happenProb;
    }

    @Override
    public NodeType type() {
        return NodeType.END;
    }

    @Override
    Boolean doExecute() {
        List<Boolean> predicts = previous.getPredicts();
        if (Objects.isNull(predicts) || predicts.size() != 1) {
            throw new IllegalStateException("结束节点输入有且只能有一个判断输入");
        }
        success = predicts.toArray(new Boolean[0])[0];
        return success;
    }

    public String getRiskName() {
        return riskName;
    }

    public void setRiskName(String riskName) {
        this.riskName = riskName;
    }

    public String getStrategy() {
        return strategy;
    }

    public void setStrategy(String strategy) {
        this.strategy = strategy;
    }

    public double getRestartProb() {
        return restartProb;
    }

    public void setRestartProb(double restartProb) {
        this.restartProb = restartProb;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public double getHappenProb() {
        return happenProb;
    }

    public void setHappenProb(double happenProb) {
        this.happenProb = happenProb;
    }
}
